//
//  UIImage+MetaData.m
//  Bigeyes
//
//  Created by 红沙尘 on 17/3/31.
//  Copyright © 2017年 红沙尘. All rights reserved.
//

#import "UIImage+MetaData.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <ImageIO/ImageIO.h>

@implementation UIImage (MetaData)

- (NSDictionary *)JPEGmetaData
{
    if (self == nil)
    {
        return nil;
    }
    
    // 转换成jpegData,信息要多一些
    NSData *jpegData              = UIImageJPEGRepresentation(self, 1.0);
    CGImageSourceRef source       = CGImageSourceCreateWithData((__bridge CFDataRef)jpegData, NULL);
    CFDictionaryRef imageMetaData = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
    CFRelease(source);
    
    NSDictionary *metaDataInfo    = CFBridgingRelease(imageMetaData);
    return metaDataInfo;
}

- (NSDictionary *)PNGmetaData
{
    if (self == nil)
    {
        return nil;
    }
    
    NSData *pngData               = UIImagePNGRepresentation(self);
    CGImageSourceRef source       = CGImageSourceCreateWithData((__bridge CFDataRef)pngData , NULL);
    CFDictionaryRef imageMetaData = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
    CFRelease(source);
    
    NSDictionary *metaDataInfo    = CFBridgingRelease(imageMetaData);
    return metaDataInfo;
}

@end
